﻿using System;
using System.Drawing;
using System.Windows.Forms;
using System.Net.Mail;

namespace MinecraftBackupAssistant.Forms
{
    public partial class ErrorReportForm : Form
    {
        private Font headerFont = new Font("Verdana", 12, FontStyle.Bold);
        private Font normalFont = new Font("Verdana", 10, FontStyle.Regular);
        private Exception exception;
    
        public ErrorReportForm(Exception ex)
        {
            exception = ex;
            InitializeComponent();
            label1.Text =
@"The application has encountered an error. Please copy this information and paste it on the forum thread.
If you think you have lost any data, try to find it at:
1. Your .minecraft\saves directory
2. " + System.IO.Path.Combine(System.IO.Path.GetTempPath(), "MinecraftBackupTemporary");
            richTextBox1.Top = label1.Top + label1.Height + 5;
            richTextBox1.Height += Math.Abs(richTextBox1.Bottom - closeButton.Top);
            richTextBox1.SelectionFont = normalFont;
            richTextBox1.SelectedText = exception.ToString().Replace(@"C:\Users\Omer\Documents\Visual Studio 2008\Projects\MinecraftBackup\MinecraftBackup\", "") + "\n\n";

            //System.Runtime.Serialization.SerializationInfo info = new System.Runtime.Serialization.SerializationInfo(e.GetType(), new System.Runtime.Serialization.FormatterConverter());
            //e.GetObjectData(info, new System.Runtime.Serialization.StreamingContext(System.Runtime.Serialization.StreamingContextStates.All));

            //foreach (var field in info)
            //{
            //    if (field.Value != null)
            //    {
            //        if (field.Name != "InnerException")
            //            addRichText(field.Name, field.Value.ToString().Replace(@"C:\Users\Omer\Documents\Visual Studio 2008\Projects\MinecraftBackup\MinecraftBackup\", ""));
            //        else
            //        {
                        
            //        }
            //    }
            //}
            //Button button = new Button();
            //button.Text = "InnerException";
            //button.AutoSizeMode = AutoSizeMode.GrowOnly;
            //button.AutoSize = true;
            //button.Top = richTextBox1.Height - button.Height - 10;
            //richTextBox1.Controls.Add(button);
            addRichText("Message: ", exception.Message);
            addRichText("Stack Trace: ", exception.StackTrace);
            if (exception.InnerException != null)
            {
                addRichText("\tInner Exception: ", "\t" + exception.InnerException.ToString());
                addRichText("\tMessage: ", "\t" + exception.InnerException.Message);
                addRichText("\tStack Trace: ", "\t" + exception.InnerException.StackTrace);
            }
        }

        private void addRichText(string header, string text)
        {
            richTextBox1.SelectionFont = headerFont;
            richTextBox1.SelectedText = header + "\n";
            richTextBox1.SelectionFont = normalFont;
            richTextBox1.SelectedText = text + "\n\n\n";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("http://minecraftbackup.codeplex.com/discussions");
        }

        private void closeButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
